package jzqb.controller;

import io.swagger.annotations.Api;
import jzqb.bo.*;
import jzqb.common.Result;
import jzqb.service.IndexService;
import jzqb.service.JSYYService;
import jzqb.service.ZTJService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/index")
@Api(tags = "首页")
public class IndexController {

    @Autowired
    IndexService indexService;

    @Autowired
    ZTJService ztjService;

    @Autowired
    JSYYService jsyyService;

    /**
     * 主页的结果集
     *
     * @return
     */
    @PostMapping("/loopResult")
    public Result loopResult() {
        List<IndexBo> indexBos = indexService.getLoopReult();
        return Result.succ(indexBos);
    }


    @PostMapping("/researchResult")
    public Result researchResult() {
        List<StandardBo> standardBos = indexService.researchResult();
        return Result.succ(standardBos);
    }


    @PostMapping("/ztjIndexResult")
    public Result getZtjIndexResult() {
        List<ZTJBo> ztjBos = ztjService.getZtjIndexResult();
        if (ztjBos == null || ztjBos.size() == 0) {
            return Result.succ(ztjBos);
        }
        for (ZTJBo ztjBo : ztjBos) {
            List<ZTBo> ztBos = ztjService.getZtList(ztjBo);
            ztjBo.setZtBos(ztBos);
        }
        return Result.succ(ztjBos);
    }


    @PostMapping("/jjyyIndexResult")
    public Result getJjyyIndexResult() {
        List<JSYYBo> standardBos = jsyyService.getJjyyIndexResult();
        return Result.succ(standardBos);
    }
}
